/*package behavior;

import lejos.nxt.*;
import lejos.robotics.subsumption.*;

public class DriveForward  implements Behavior {
   private boolean suppressed = false;
   
   public boolean takeControl() {
      return true;
   }

   public void suppress() {
      suppressed = true;
   }

   public void action() {
     suppressed = false;
     Motor.A.forward();
     Motor.C.forward();
     while( !suppressed )
        Thread.yield();
     Motor.A.stop(); // clean up
     Motor.C.stop();
   }
}*/
package behavior;

import lejos.nxt.LightSensor;
import lejos.nxt.MotorPort;
import lejos.nxt.NXTRegulatedMotor;
import lejos.nxt.SensorPort;
import lejos.nxt.comm.RConsole;
import lejos.robotics.subsumption.*;
import motor.carrito;

public class FollowLine  implements Behavior {
   private boolean suppressed = false;
   private carrito carro;
   NXTRegulatedMotor barredora;
   LightSensor luz;
   
   public FollowLine(carrito carro){
	   this.carro = carro;
	   //this.barredora = new NXTRegulatedMotor(MotorPort.B);
	   this.luz = new LightSensor(SensorPort.S1);
   }
   
   public boolean takeControl() {
	  //RConsole.println("Tome control de DRIVEFORWARD");
	  return (luz.getLightValue() <= 60 );
	  
   }

   public void suppress() {
	  //RConsole.println("Suprimo DRIVEFORWARD");
	  suppressed = true;	
   }

   public void action() {
	 //RConsole.println("Acción de DRIVEFORWARD");
     suppressed = false;
     carro.SetMovingSpeed(100);
     //carro.Forward();
     //barredora.setSpeed(758);
	 //barredora.forward();
     int valueLight;
	 //while( !suppressed )
     //{
				 
		 valueLight = luz.getLightValue();
		 RConsole.println(Integer.toString(valueLight));
    	 if(valueLight < 50 ){
    		 carro.TurnLeft(10);
    	 }else if(valueLight > 60 ){
    		 carro.TurnRight(30);
    	 }
    	 carro.Forward();
    	 Thread.yield();
     //}
        
     //barredora.stop();
     //carro.Stop();
   }
}
